package deployr.cli;

import deployr.core.*;
import deployr.domain.*;

public class ReadUpdateChecksumResponder extends Responder {

	private final Workspace workspace;

	public ReadUpdateChecksumResponder(Workspace workspace) {
		this.workspace = workspace;
	}

	@Override
	protected Result respondTo(String method, String requestURI, Input input) {

		String updateKey = requestURI.replaceAll(".*/updates/", "").replaceAll("/checksum.*", "");

		IUpdate update = workspace.findUpdate(updateKey);

		return new Result(200, update.getChecksum());
	}

	@Override
	protected boolean shouldRespond(String method, String requestURI) {
		return "GET".equals(method) && requestURI.matches(".*/updates/.*/checksum.*");
	}

}
